// 1629. 按键持续时间最长的键
// 思路：一次遍历同时维护时间间隔最长 与 对应的字母

#include <vector>
#include <string>
using namespace std;

class Solution
{
public:
    char slowestKey(vector<int>& releaseTimes, const string& keysPressed)
    {
        int max = releaseTimes[0];
        char ret = keysPressed[0];
        for(int i = 1; i < releaseTimes.size(); i++)
        {
            int gap = releaseTimes[i] - releaseTimes[i - 1];
            if(gap > max) max = gap, ret = keysPressed[i];
            else if(gap == max && keysPressed[i] > ret) ret = keysPressed[i];
        }
        return ret;
    }
};